home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / cd2xspeed / CD2XSpeed.c < prev    next >
C/C++ Source or Header  |  1999-10-26  |  4KB  |  204 lines

  1. Date; /*
  2.  
  3. SC LINK MODIFIED NOSTKCHK NOICONS CD2XSpeed
  4. quit
  5.  
  6. */
  7.  
  8. /*********************************
  9.            CD2XSpeed.c
  10.  
  11.  Turn cd double read speed on/off.
  12.  
  13.           W.D.L 930420
  14. **********************************/
  15.  
  16. // 930916    Now goes away quietly upon failure, so its always safe to use.
  17.  
  18. /*
  19.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1993-1999
  20.  * Amiga, Inc.  All rights reserved.
  21.  *
  22.  * DISCLAIMER: This software is provided "as is".  No representations or
  23.  * warranties are made with respect to the accuracy, reliability, performance,
  24.  * currentness, or operation of this software, and all use is at your own risk.
  25.  * Neither Amiga nor the authors assume any responsibility or liability
  26.  * whatsoever with respect to your use of this software.
  27.  */
  28.  
  29. // Tab size is 8!
  30.  
  31. #include <exec/types.h>
  32. #include <exec/memory.h>
  33. #include <exec/io.h>
  34. #include <dos/dos.h>
  35.  
  36. #include <clib/exec_protos.h>
  37. #include <clib/alib_protos.h>
  38. #include <clib/dos_protos.h>
  39.  
  40. #include <pragmas/exec_pragmas.h>
  41.  
  42. #include "devices/cd.h"
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>    // for setmem()
  47.  
  48. #include "cd2xspeed_rev.h"
  49.  
  50. #define TEMPLATE    "ON/S,OFF/S" VERSTAG " Wayne D. Lutz"
  51. #define    OPT_ON        0
  52. #define    OPT_OFF        1
  53. #define    OPT_COUNT    2
  54.  
  55. STATIC LONG          opts[OPT_COUNT];
  56. STATIC struct RDArgs    * rdargs;
  57. STATIC struct Device    * CDDevice;
  58. STATIC struct MsgPort    * CDPort;
  59. STATIC struct IOStdReq    * CDDeviceMReq;
  60.  
  61. IMPORT struct Library * SysBase;
  62.  
  63. /*
  64.  *  SendIOR -- asynchronously execute a device command
  65.  */
  66. BOOL
  67. SendIOR( struct IOStdReq * req, LONG cmd, ULONG off, ULONG len, APTR data)
  68. {
  69.     req->io_Command = cmd;
  70.     req->io_Offset = off;
  71.     req->io_Length = len;
  72.     req->io_Data   = data;
  73.  
  74.     SendIO( (struct IORequest *)req);
  75.  
  76.     if ( req->io_Error ) {
  77. //    printf("SendIOR() ERROR!!! io_Error= %ld\n",req->io_Error);
  78.     return( FALSE );
  79.     } else {
  80.     return( TRUE );
  81.     }
  82.  
  83. } // SendIOR()
  84.  
  85. /*
  86.  * Send a CD_CONFIG command to cd.device.
  87.  */
  88. BOOL
  89. CDConfig( ULONG tag, ... )
  90. {
  91.     SendIOR( CDDeviceMReq, CD_CONFIG, NULL, 0, &tag );
  92.  
  93.     if ( CDDeviceMReq->io_Error ) {
  94. //    printf("\n!!!CD_CONFIG ERROR!!! io_Error= %ld\n\n",CDDeviceMReq->io_Error);
  95.     return( FALSE );
  96.     }
  97.  
  98.     WaitIO( (struct IORequest *)CDDeviceMReq );
  99.  
  100.     return( TRUE );
  101.  
  102. } // CDConfig()
  103.  
  104.  
  105. /*
  106.  * Close cd.device.
  107.  */
  108. VOID
  109. CDDeviceTerm( VOID )
  110. {
  111.     if ( CDDeviceMReq ) {
  112.     if ( CDDevice ) {
  113.  
  114.         CloseDevice( (struct IORequest *)CDDeviceMReq );
  115.         CDDevice = NULL;
  116.     }
  117.  
  118.     DeleteStdIO( CDDeviceMReq );
  119.     CDDeviceMReq = NULL;
  120.     }
  121.  
  122.     if ( CDPort ) {
  123.     DeleteMsgPort( CDPort );
  124.     CDPort = NULL;
  125.     }
  126.  
  127. } // CDDeviceTerm()
  128.  
  129.  
  130. /*
  131.  * Attempts to open cd.device if not already opened.
  132.  * Returns:
  133.  *    retcode: (BOOL) reflects device's open state.
  134.  *  *opened: (BOOL) TRUE if opened by this call.
  135.  */
  136. BOOL
  137. CDDeviceInit( ULONG * opened )
  138. {
  139.     if ( opened )
  140.     *opened = FALSE;
  141.  
  142.     if ( !CDDevice ) {
  143.  
  144.     if ( CDPort = CreateMsgPort() ) {
  145.         if ( CDDeviceMReq = CreateStdIO( CDPort ) ) {
  146.  
  147.         if ( !OpenDevice( "cd.device", 0, (struct IORequest *)CDDeviceMReq, 0 ) ) {
  148.             CDDevice = CDDeviceMReq->io_Device;
  149.         }
  150.         }
  151.     }
  152.  
  153.     if ( !CDDevice ) {
  154.         return( FALSE );
  155.     }
  156.  
  157.     if ( opened )
  158.         *opened = TRUE;
  159.     }
  160.  
  161.     return( TRUE );    
  162.  
  163. } // CDDeviceInit()
  164.  
  165.  
  166. VOID
  167. main( LONG argc,char * argv[] )
  168. {
  169.     int speed;
  170.  
  171.     // workbench
  172.     if ( argc == 0 )
  173.     exit( RETURN_OK );
  174.  
  175.     if ( SysBase->lib_Version < 36 )
  176.     exit( RETURN_OK );
  177.  
  178.     setmem( opts, sizeof (opts) ,0 );
  179.  
  180.     rdargs = ReadArgs(TEMPLATE, opts, NULL);
  181.  
  182.     if ( !rdargs ) {
  183.     PrintFault(IoErr(), NULL);
  184.     exit( RETURN_OK );
  185.     }
  186.  
  187.     if ( !CDDeviceInit( NULL ) ) {
  188. //    printf("Could NOT open cd.device Aborting\n");
  189.     exit( RETURN_OK );
  190.     }
  191.  
  192.     speed = opts[OPT_OFF] ? 75 : 150;
  193.  
  194.     CDConfig( TAGCD_READSPEED, speed, 0 );
  195.  
  196.     CDDeviceTerm();
  197.  
  198.     FreeArgs( rdargs );
  199.  
  200.     exit( RETURN_OK );
  201.  
  202. } // main()
  203.  
  204.